<template>
    <el-select v-model="sval" :disabled="disabled" :class="className" :popper-class="popperClass" clearable placeholder="请选择公司" :style="{width}" @change="onChcange">
        <el-option v-for="dt in lists" :key="dt.companyId" :value="dt.companyId" :label="dt.companyName" />
    </el-select>
</template>
<script setup>
import {ref,onMounted,watch} from "vue"
import {getCompanyList} from '@/api/system'

const props = defineProps({
    modelValue:'',
    width:{
        type:String,
        default:'100%'
    },
    className:'',
    popperClass:"",
    disabled:{
        type:Boolean,
        default:false
    }
})
const emit = defineEmits(['update:modelValue','change'])
const sval = ref('')
const lists = ref('')

onMounted(()=>{   
    getTableData()
})

watch(()=>props.modelValue,(n,o)=>{
    sval.value = n
})

const getTableData = async () => {
  const res = await getCompanyList({ page: 1, limit: 1000000})
  if (res.code == 0) {
    lists.value = res.data
    sval.value = props.modelValue || '' // 设置默认选项
  }
}

const onChcange = ()=>{
    emit('update:modelValue',sval.value) 
    emit('change',sval.value) 
}

defineExpose({getTableData})

</script>

<style scoped lang="scss">
</style>